﻿using Aop.Api;
using System;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using models;
using BLL;

namespace APPZF.pagepay
{
    public partial class pagepay1 : System.Web.UI.Page
    {
        PayManager marager = new PayManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            string ddh = Session["ddh"].ToString();//接受订单号
            string id = Session["sessid"].ToString();//接受用户ID
            List<Pay> la= marager.SelPay(id, ddh); //显示出订单
            Pay PaySum = marager.SumCart(id, ddh);//总价
            DefaultAopClient client = new DefaultAopClient(config.URL, config.APPID, config.RSA_PRIVATE_KEY, "json", "1.0", config.SIGNTYPE, config.ALIPAY_PUBLIC_KEY, config.CHARSET, false);
            // 外部订单号，商户网站订单系统中唯一的订单号
            string out_trade_no = ddh;

            // 订单名称
            string subject = la[0].ProName;

            // 付款金额
            string total_amount = PaySum.ProPrice.ToString();

            // 商品描述
            string body = la[0].ProName.Trim();

            // 组装业务参数model
            AlipayTradePagePayModel model = new AlipayTradePagePayModel();
            model.Body = body;
            model.Subject = subject;
            model.TotalAmount = total_amount;
            model.OutTradeNo = out_trade_no;
            model.ProductCode = "FAST_INSTANT_TRADE_PAY";

            AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
            // 设置同步回调地址
            request.SetReturnUrl("https://localhost:44370/success.aspx");
            // 设置异步通知接收地址
            request.SetNotifyUrl("https://localhost:44370/information.aspx");
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradePagePayResponse response = null;
            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }


        }
        protected void BtnAlipay_Click(object sender, EventArgs e)
        {

        }
    }
}